import Vue from 'vue'
import VueRouter from "vue-router";


import FooterIndex from '@/views/FooterIndex'
import Index from '@/views/Index'
import House from '@/views/House'
import InforMation from '@/views/InforMation'
import HomeIndex from '@/views/HomeIndex'


//城市列表索引
import CityDemo from '@/views/CityDemo'
// 登录
import { getToken } from '@/utils/stronage';
import RegiseTred from '@/views/RegiseTred'
import Login from '@/views/Login'
import HouseDetails from '@/views/HouseDetails'
Vue.use(VueRouter)

const router = new VueRouter({
    routes: [{
            path: '/',
            redirect: '/footer'
        },
        {
            path: '/footer',
            component: FooterIndex,
            redirect:'/index',
            children: [{
                    path: '/index',
                    component: Index
                },
                {
                    path: '/house',
                    component: House,

                }, {
                    path: '/information',
                    component: InforMation
                }, {
                    path: '/home',
                    component: HomeIndex
                }
            ]
        },
        {
            path: '/housedetails/:id?',
            component: HouseDetails

        },
        {
            path:'/registred',
            component:RegiseTred
        },
        {
            path:'/login',
            component:Login
        },
        {
            path:'/city',
            component:CityDemo
        }
    ],
    // mode: 'history'
    // linkActiveClass:'active'
})
const whiteList = ['/login', '/registred', '/index']

router.beforeEach((to, from, next) => {
//   // to  到哪去
//   // from 从哪来
//   // next  能不能继续
// //   console.log(to)
// //   console.log(from)

//   if (to.path === '/login') {
//     next('/register')
//   } else {
//     next()
//   }
//   next()
  const gettoken = getToken()
  if (gettoken) {
    next()
  } else {
    if (whiteList.includes(to.path)) {
      next()
    } else {
      next('/login')
    }
  }
})


export default router